package com.sky.controller.admin;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺营业状态管理")
@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        redisTemplate.opsForValue().set(ShopStatusConstant.KEY_SHOP_STATUS,status);
        log.info("设置营业状态：{}",status == 1 ? "营业中":"打烊了");
        return Result.success();
    }

    @GetMapping("/status")
    public Result getStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get(ShopStatusConstant.KEY_SHOP_STATUS);
        log.info("获取营业状态：{}",status == 1 ? "营业中":"打烊了");
        return Result.success(status);
    }
}
